import json


class change_format:
    def __init__(self):
        pass

    def to_camel_case(self, snake_str):
        components = snake_str.split('_')
        return components[0] + ''.join(x.title() for x in components[1:])

    def to_snake_case(self, camel_str):
        result = []
        for char in camel_str:
            if char.isupper():
                result.append('_')
                result.append(char.lower())
            else:
                result.append(char)
        return ''.join(result)

    def changes_format(self, obj, to_snake=False):
        if isinstance(obj, dict):
            new_obj = {}
            for key, value in obj.items():
                if to_snake:
                    new_key = self.to_snake_case(key)  # 转换成snake_case
                else:
                    new_key = self.to_camel_case(key)  # 转换成camelCase
                new_obj[new_key] = self.changes_format(value, to_snake)  # 递归处理嵌套
            return new_obj
        elif isinstance(obj, list):
            return [self.changes_format(item, to_snake) for item in obj]  # 递归处理列表
        else:
            return obj  # 如果不是字典或列表，直接返回
